package com.scau.ums.controller;

import com.scau.ums.mapper.MaintainerMapper;
import com.scau.ums.model.Maintainer;
import com.scau.ums.model.Repairreport;
import com.scau.ums.service.imp.RepairReport.RepairReportImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AnalyseFinishedReportController {

    @Autowired
    private MaintainerMapper maintainerMapper;

    @Autowired
    private RepairReportImp repairReportImp;
    @RequestMapping(value="AnalyzeFinishedReports")
    public String AnalyzeFinishedReports(){
        return "AnalyzeFinishedReports";
    }

    @RequestMapping(value="showAnalysis")
    @ResponseBody
    public ArrayList showAnalysis(HttpServletRequest request){
        String periodType=request.getParameter("periodType");
        String reportType=request.getParameter("reportType");
        String reporterType=request.getParameter("reporterType");
        List<Repairreport> CustomedFinishedReports=repairReportImp.getCustomedFinishedReports(periodType,reportType,reporterType);

        for (Repairreport a:
                CustomedFinishedReports) {
            System.out.println(CustomedFinishedReports);
        }








        int likeNumber=repairReportImp.getLikeNumber();
        int unlikeNumber=repairReportImp.getUnLikeNumber();
        Map<String,Integer> StuAnalysisMap=repairReportImp.getStuAnalysisMap();
        Map<String,Integer> TeaAnalysisMap=repairReportImp.getTeaAnalysisMap();
        int LikeNumber=repairReportImp.getLikeNumber();
        int UnLikeNumber=repairReportImp.getUnLikeNumber();
        request.setAttribute("LikeNumber",LikeNumber);
        request.setAttribute("UnLikeNumber",UnLikeNumber);

        System.out.println("getSomeoneLikeNumber======================"+repairReportImp.getSomeoneLikeNumber(5));
        System.out.println("getSomeoneUnLikeNumber======================"+repairReportImp.getSomeoneUnlikeNumber(5));

        request.setAttribute("CustomedFinishedReports",CustomedFinishedReports);
        request.setAttribute("StuAnalysisMap",StuAnalysisMap);


        List<Maintainer> maintainersInfo=maintainerMapper.selectByExample(null);

        for(Maintainer maintainer:maintainersInfo){
            maintainer.setLikeNumber(repairReportImp.getSomeoneLikeNumber(Integer.valueOf(maintainer.getId())));
            maintainer.setUnLikeNumber(repairReportImp.getSomeoneUnlikeNumber(Integer.valueOf(maintainer.getId())));
        }


        ArrayList list=new ArrayList();
        list.add(CustomedFinishedReports);
        list.add(StuAnalysisMap);
        list.add(TeaAnalysisMap);
        list.add(periodType);
        list.add(reportType);
        list.add(reporterType);

        list.add(LikeNumber);
        list.add(UnLikeNumber);
        list.add(maintainersInfo);

        return list;
    }
}
